package com.googlecode.wmlynar.j2meunitgenerator.maven;

import java.io.IOException;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

import com.googlecode.wmlynar.j2meunitgenerator.TestsScanner;


/**
 * A Mojo for generating J2meUnit test suite that executes all tests in the given project.
 *
 * @author Wojciech Mlynarczyk
 * @goal generate
 * @phase generate-sources
 * @requiresDependencyResolution compile
 */
public class GeneratorMojo extends AbstractMojo {

    /**
     * @parameter
     * @required
     */
    private TestSuite[] testSuites;

    public void execute() throws MojoExecutionException, MojoFailureException {
    	try {
    	    for(TestSuite testSuite : testSuites) {
    	        TestsScanner.generateFile(testSuite.getTestsDirectory(), testSuite
                        .getTargetDirectory(), testSuite.getClassName());
            }
		} catch (IOException e) {
			throw new MojoExecutionException(e.toString());
		}
    }
}
